<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // class dialof {
        //     constructor(name) {
        //         this.name = name
        //     }
        // }

        // let ins = null;

        // function singleton() {
        //     if (!ins) ins = new dialof('tt')
        //     return ins
        // }

        // const a = singleton()
        // const a1 = singleton()
        // console.log(a, a1);
        // console.log(a === a1);

        const Person = (function outer() {
            class Person {
                constructor() {
                    this.name = 'jack'
                }
                setName(val) {
                    this.name = val
                }
            }
            let instance = null;
            return function inner(uname) {
                if (!instance) instance = new Person();
                instance.setName(uname)
                return instance;
            }
        })();
        const p1 = new Person('ls');
        console.log(p1);
        const p2 = new Person('zs');
        console.log(p2);
        console.log(p1 === p2);
    </script>
</body>

</html>